package io;

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * 缓冲输出流的缓冲区问题
 */
public class FlushDemo {
    public static void main(String[] args) throws IOException {
        FileOutputStream fos = new FileOutputStream("bos.txt");
        BufferedOutputStream bos =new BufferedOutputStream(fos);
        String line ="rush!";
        byte[] bytes = line.getBytes(StandardCharsets.UTF_8);
        bos.write(bytes);
        bos.flush();//强制性让文件写入一次
        System.out.println("写出完毕");
        //缓冲流的close方法 会自动调用一次flush();
        bos.close();
    }
}
